﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sita.Data.Repositories;
using Sita.Entities;

namespace Sita.MainModule.Services
{
    public class CustomerService
    {
        CustomerRepository CustomerRepository;

        public CustomerService()
        {
            CustomerRepository = new CustomerRepository();
        }

        public IList<Customer> GetPaginatedCustomersByBussinesUnitID(int businessUnitID, int pageIndex, int pageSize, string sortColumn, bool ascending, out int totalRows)
        {
            return CustomerRepository.GetPaginatedByBusinessUnitID(businessUnitID, pageIndex, pageSize, sortColumn, ascending, out totalRows);
        }

        public IList<Customer> GetPaginatedByFilter(int businessUnitID, int pageIndex, int pageSize, string sortColumn, bool ascending, string firstName,
            string lastName, int dni, string phone, string email, out int totalRows)
        {
            return CustomerRepository.GetPaginatedByFilter(businessUnitID, pageIndex, pageSize, sortColumn, ascending, firstName, lastName, dni, phone, email, out totalRows);
        }

        public int AddCustomer(Customer customer)
        {
            CustomerRepository.Add(customer);

            CustomerRepository.StoreContext.Commit();

            return customer.CustomerID;
        }

        public Customer GetCustomerByIDWithVehicles(int customerID)
        {
            return CustomerRepository.GetByIDWithVehicles(customerID);
        }

        public Customer GetCustomerByID(int customerID)
        {
            return CustomerRepository.GetByID(customerID);
        }

        public IList<Customer> GetCustomersByBusinessUnitID(int businessUnitID, string sortColumn)
        {
            return CustomerRepository.GetByBusinessUnitIDByCompanyName(businessUnitID, string.Empty, sortColumn);
        }

        public IList<Customer> GetCustomersByBusinessUnitIDByCompanyName(int businessUnitID, string companyName, string sortColumn)
        {
            return CustomerRepository.GetByBusinessUnitIDByCompanyName(businessUnitID, companyName, sortColumn);
        }

        public bool ModifyCustomer(Customer customer)
        {
            CustomerRepository.Modify(customer);

            CustomerRepository.StoreContext.Commit();

            return true;
        }

        public bool DeleteCustomer(Customer customer)
        {
            CustomerRepository.Delete(customer);

            CustomerRepository.StoreContext.Commit();

            return true;
        }
    }
}
